import QtQuick 2.0
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3
Rectangle{
    property int thirdMenuItemWidth: 120
    property color thirdMenuBgColor: "#CC393E39"
    property int thirdMenuItemHeight: 30
    property int thirdMenuContentLeftMargin: 30
    property string thirdMenuTextFont: "微软雅黑"
    property int thirdMenuTextSize: 12
    property color thirdMenuTextColor: "#FFF"
    property color thirdMenuTextPressedColor: "#F00"
    property string thirdMenuText: ""
    property color normalColor: "#FFF"
    property color hoverColor: "#5be7c4"
    property bool hasCheckBox: false
    property bool checkBoxChecked: false
    property var mouseclick:function(){}
    property var mouseToggle: function(toggled){}
    property var setChecked: function(toggled){
        check.checked = toggled;
    }
    property var hoverlick:function(){}
    //定义变量 是否启用这个功能
    property bool hasChoseBox: false

    width: thirdMenuItemWidth
    height: thirdMenuItemHeight
    color: thirdMenuBgColor
    CheckBox{

        id: check
        visible: hasCheckBox
        checked: checkBoxChecked
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.verticalCenter: parent.verticalCenter
        style: CheckBoxStyle{
            indicator: Rectangle {
                            implicitWidth: 14
                            implicitHeight: 14
                            radius: 3
                            border.color: control.activeFocus ? "darkblue" : "gray"
                            border.width: 1
                            Rectangle {
                                visible: control.checked
                                color: "#555"
                                border.color: "#333"
                                radius: 1
                                anchors.margins: 4
                                anchors.fill: parent
                            }
                    }
        }
    }

    Text{
        id: menuTxt
         width: thirdMenuItemWidth
         height: thirdMenuItemHeight
         anchors.left: parent.left
         anchors.leftMargin: thirdMenuContentLeftMargin
         font.family: thirdMenuTextFont
         font.pixelSize: thirdMenuTextSize
         color: thirdMenuTextColor
         text: thirdMenuText
         verticalAlignment: Text.AlignVCenter
    }
    MouseArea{
        anchors.fill: parent
        hoverEnabled: true
        onEntered:{
            menuTxt.color = hoverColor
            hoverlick()
        }
        onExited: {
            menuTxt.color = normalColor
        }
        onClicked: {
            if(!hasChoseBox)
            {
                menu.closeSubMenu()
            }
            if(!hasCheckBox){
                menu.closeAllSubMenu()
                mouseclick()
            }
            else{
                check.checked = !check.checked
                mouseToggle(check.checked)

            }
        }
    }
}

